/*
 * Copyright 2010-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.pathlet.core;

/**
 * <p>
 * Definition of an interface for Resource Factory.
 * </p>
 *
 * <p>
 * <p>
 * 概念解释：
 * <em>ResourceFactory</em> 不创建真正的资源实例它创建的是资源模板（PathletResource)。
 * 被ResourceFactory创建的<code>{@link PathletResource}</code>可以定位到对应的资源，由PathletResource的方法才能创建真正的资源实例。
 * <code>{@link PathletResource}</code>的实现类，提供了唯一创建资源实例的方法newInstance()。
 * </p>
 * <p>
 * And what's the difference between the resource and the resource target?
 * Please reference the <code>{@link PathletResource}</code>.
 * </P>
 *
 * @author Chenlong Zhang
 * @since 2012-11-29
 */
public interface ResourceFactory {

	PathPattern MATCH_PATTERN_ALL = new PathPattern(new String[]{"/**/*"}, null, "/");

	/**
	 * get the parent PathletContainer.
	 */
	PathletContainer getContainer();

	/**
	 * set the parent PathletContainer.
	 */
	void setContainer(PathletContainer container);

	/**
	 * Get PathPattern to filter the match resources by paths.
	 * In generally, it could return pattern same like <code>/&#42;&#42;/&#42;Service</code>.
	 *
	 * @return
	 */
	PathPattern getPathPattern();

	/**
	 * Check the path is match the PathPattern.
	 * @param path
	 * @return
	 */
	default boolean isPathMatch(Path path) {
		PathPattern pattern = getPathPattern();
		if(pattern == null) {
			return true;
		}
		else {
			return pattern.isMatch(path);
		}
	}

	/**
	 *
	 * Default resource scope for a none scope specified resource.
	 *
	 * @return
	 */
	String getDefaultScope();

}
